package com.ems.util;

import java.awt.BasicStroke;
import java.awt.Color;

import jxl.write.Colour;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.ThermometerPlot;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.RectangleInsets;

public class ThermometerChart {
	public static JFreeChart chart(double data,String itemUnit,String itemName,double alarmUp,double alarmDown){ 
		if(alarmUp==0){alarmUp=100.0D;}
	DefaultValueDataset defaultvaluedataset = new DefaultValueDataset(data);
    ThermometerPlot thermometerplot = new ThermometerPlot(defaultvaluedataset);
    thermometerplot.setBackgroundPaint(new Color(229,243,252));
    thermometerplot.setOutlineVisible(false);
    //thermometerplot.setValuePaint(Color.red);
  //  thermometerplot.setInsets(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));
//    thermometerplot.setPadding(new RectangleInsets(10.0D, 10.0D, 10.0D, 10.0D));
//    thermometerplot.setThermometerStroke(new BasicStroke(2F));
    thermometerplot.setThermometerPaint(new Color(192,192,192));
    
    
    thermometerplot.setUnits(0);
    thermometerplot.setGap(3);
    thermometerplot.setRange(0D, 100.0D);
    thermometerplot.setSubrange(0, 0D, alarmDown);
    thermometerplot.setSubrangePaint(0, Color.red);
    thermometerplot.setSubrange(1, alarmDown, alarmUp);
    thermometerplot.setSubrangePaint(1, Color.green);
    thermometerplot.setSubrange(2, alarmUp, 100.0D);
    thermometerplot.setSubrangePaint(2, Color.red);
    
    
    JFreeChart chart = new JFreeChart(itemName+"("+itemUnit+")", thermometerplot);
    chart.setBackgroundPaint(new Color(229,243,252));
    chart.setBorderVisible(false);
    return chart;
	}
}
